package com.bb.blog.security.client;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;


import org.springframework.stereotype.Component;


@RequiredArgsConstructor
@Component
@Slf4j
public class RedisOAuth2AuthorizedClientService {
//public class RedisOAuth2AuthorizedClientService implements  OAuth2AuthorizedClientService {
//
//    private static final String DEFAULT_AUTHORIZED_CLIENTS_ATTR_NAME =
//            HttpSessionOAuth2AuthorizedClientRepository.class.getName() +  ".AUTHORIZED_CLIENTS";
//    private final String sessionAttributeName = DEFAULT_AUTHORIZED_CLIENTS_ATTR_NAME;
//
//    private final RedisTemplate<Object,Object> redisTemplate;
//
//    private static  Long VALID_TIME = 5 * 60L;
//
//    /**
//     * 认证code 的有效时间 默认300秒
//     * @param validTime
//     */
//    @Value(value = "${auth.code.validTime:300}")
//    public static void setValidTime(Long validTime) {
//        VALID_TIME = validTime;
//    }
//
//
//
//
//    @Override
//    public <T extends OAuth2AuthorizedClient> T loadAuthorizedClient(String clientRegistrationId, String principalName) {
//        String key =  getIdentifier(clientRegistrationId,principalName);
//        Assert.hasText(clientRegistrationId, "clientRegistrationId cannot be empty");
//        Assert.hasText(principalName, "principalName cannot be empty");
//
//        return (T) this.redisTemplate.opsForValue().get(key);
//    }
//
//    @Override
//    public void saveAuthorizedClient(OAuth2AuthorizedClient authorizedClient, Authentication principal) {
//        Assert.notNull(authorizedClient, "authorizedClient cannot be null");
//        Assert.notNull(principal, "principal cannot be null");
//        this.redisTemplate.opsForValue().set(this.getIdentifier(
//                authorizedClient.getClientRegistration().getRegistrationId(), principal.getName()),
//                authorizedClient,VALID_TIME, TimeUnit.SECONDS);
//    }
//
//    @Override
//    public void removeAuthorizedClient(String clientRegistrationId, String principalName) {
//        Assert.hasText(clientRegistrationId, "clientRegistrationId cannot be empty");
//        Assert.hasText(principalName, "principalName cannot be empty");
//            this.redisTemplate.delete(this.getIdentifier(clientRegistrationId, principalName));
//    }
//    private String getIdentifier(String registrationId, String principalName) {
//        String identifier = RedisOAuth2AuthorizedClientService.class + "[" + registrationId + "][" + principalName + "]";
//        log.debug("identifier : " + identifier);
//        return identifier;
//    }

}
